<?php defined('BASEPATH') OR die('No direct access allowed.');
/**
 * Description of "create-branches"
 *
 * Created on Dec 20, 2010
 * @author Ramon Gutierrez
 * @copyright Bitstop Network Services Inc.
 * @version 0.1
 */
?>

            <script type="text/javascript">
			  // <![CDATA[
			  $(document).ready(function() {
			    var use_same = true;
				
				$("#use_same").change(function() {
			      use_same = $(this).attr("checked");
				  
				  if(use_same) {
					$("#a_street_address").val($("#street_address").val()).attr("readonly", "readonly").css("fontStyle", "italic");
			        $("#a_city").val($("#city").val()).attr("readonly", "readonly").css("fontStyle", "italic");
					$("#a_state").val($("#state").val()).attr("readonly", "readonly").css("fontStyle", "italic");
					$("#a_country_id").val($("#country_id").val()).attr("readonly", "readonly").css("fontStyle", "italic");
					$("#a_zip").val($("#zip").val()).attr("readonly", "readonly").css("fontStyle", "italic");
					$("#a_contact_number").val($("#contact_number").val()).attr("readonly", "readonly").css("fontStyle", "italic");
				  } else {
					$("#a_street_address").attr("readonly", "").css("fontStyle", "");
					$("#a_city").attr("readonly", "").css("fontStyle", "");
					$("#a_state").attr("readonly", "").css("fontStyle", "");
					$("#a_country_id").attr("readonly", "").css("fontStyle", "");
					$("#a_zip").attr("readonly", "").css("fontStyle", "");
					$("#a_contact_number").attr("readonly", "").css("fontStyle", "");
				  }
				});
				
				$(".ci").change(function() {
				  if(use_same) {
			        $("#a_" + $(this).attr("id")).val($(this).val());
				  }
				});
				
				$(".ci").keyup(function() {
				  if(use_same) {
			        $("#a_" + $(this).attr("id")).val($(this).val());
				  }
				});
				
				$("#use_same").change();
				
				$("#company").autocomplete('<?php echo site_url('branches/getCompanies'); ?>', { mustMatch: true, delay: 10 });
			  });
			// ]]>
			</script>
            <div id="body">
              <div class="sectionhead"><?php echo $this->lang->line('subtitle_create_branch'); ?></div>
              <div id="response"></div>
              <form id="theform" method="post" action="<?php echo site_url($module . '/create_ajax'); ?>">
              <div style="margin-bottom: 10px;">
                <span class="label" style="display: inline-block; font-weight: normal;"><input checked="checked" type="checkbox" name="use_same" id="use_same" style="margin-right: 5px;" /><?php echo $this->lang->line('use_same_info'); ?></span>
              </div>
              <div class="row">
                <div class="firstcol">
                  <div>
                    <span class="label"><?php echo $this->lang->line('branch_name'); ?></span>
                    <input class="standard" style="font-weight: bold;" type="text" size="25" name="name" maxlength="64" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('street_address'); ?></span>
                    <input class="standard ci" type="text" size="50" id="street_address" name="street_address" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('city'); ?></span>
                    <input class="standard ci" type="text" size="50" id="city" name="city" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('state'); ?></span>
                    <input class="standard ci" type="text" size="50" id="state" name="state" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('country'); ?></span>
                    <select class="standard ci" name="country_id" id="country_id">
                    <?php foreach($countries->result_array() as $row): ?>
                    <?php $selected = ($row['id'] == $this->session->userdata('country_id') ? ' selected="selected"' : ''); ?>
                    <?php echo '<option value="' . $row['id'] . '"' . $selected . '>' . $row['name'] . " ($row[abbreviation])" . '</option>'; ?>
                    <?php endforeach; ?>
                    </select>
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('zipcode'); ?></span>
                    <input class="standard ci" type="text" size="15" id="zip" name="zip" maxlength="10" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('contact_number'); ?></span>
                    <input class="standard ci" type="text" size="25" id="contact_number" name="contact_number" maxlength="32" />
                  </div>
                  <?php if($this->session->userdata('account_type') == 'site_admin'): ?>
                  <div>
                    <span class="label"><?php echo $this->lang->line('company'); ?></span>
                    <input class="standard" type="text" size="50" name="company" id="company" />
                  </div>
                  <?php endif; ?>
                </div>
                <div class="nextcol" style="border-left: 1px solid #333333; padding: 8px 0 8px 15px; margin-top: -8px; margin-bottom: -8px;">
                  <div>
                    <div class="firstcol">
                      <div>
                        <span class="label"><?php echo $this->lang->line('first_name'); ?></span>
                        <input class="standard" type="text" size="25" name="a_first_name" maxlength="32" />
                      </div>
                    </div>
                    <div class="nextcol">
                      <div>
                        <span class="label"><?php echo $this->lang->line('last_name'); ?></span>
                        <input class="standard" type="text" size="25" name="a_last_name" maxlength="32" />
                      </div>
                    </div>
                    <div class="clear" style="height: 0px;"></div>
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('street_address'); ?></span>
                    <input class="standard" type="text" size="50" id="a_street_address" name="a_street_address" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('city'); ?></span>
                    <input class="standard" type="text" size="50" id="a_city" name="a_city" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('state'); ?></span>
                    <input class="standard" type="text" size="50" id="a_state" name="a_state" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('country'); ?></span>
                    <select class="standard" name="a_country_id" id="a_country_id">
                    <?php foreach($countries->result_array() as $row): ?>
                    <?php $selected = ($row['id'] == $this->session->userdata('country_id') ? ' selected="selected"' : ''); ?>
                    <?php echo '<option value="' . $row['id'] . '"' . $selected . '>' . $row['name'] . " ($row[abbreviation])" . '</option>'; ?>
                    <?php endforeach; ?>
                    </select>
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('zipcode'); ?></span>
                    <input class="standard" type="text" size="15" id="a_zip" name="a_zip" maxlength="10" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('contact_number'); ?></span>
                    <input class="standard" type="text" size="25" id="a_contact_number" name="a_contact_number" maxlength="32" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('email'); ?></span>
                    <input class="standard" type="text" size="25" name="a_email" maxlength="64" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('signup_account_details'); ?></span>
                    <div style="padding: 5px 10px; border: 1px solid #999999; display: inline-block;">
                      <div>
                        <span class="label"><?php echo $this->lang->line('username'); ?></span>
                        <input class="standard" type="text" size="25" id="acct_username" name="acct_username" maxlength="32" />
                      </div>
                      <div>
                        <span class="label"><?php echo $this->lang->line('password'); ?></span>
                        <input class="standard" type="password" size="25" id="acct_password" name="acct_password" maxlength="32" />
                      </div>
                      <div>
                        <span class="label"><?php echo $this->lang->line('confirm_password'); ?></span>
                        <input class="standard" type="password" size="25" id="acct_confirm" name="acct_confirm" maxlength="32" />
                      </div>
                    </div>
                  </div>
                </div>
                <div style="clear: both;"></div>
              </div>
              <div style="margin-top: 8px; font-size: 0.9em;">
                <div class="firstcol">
                  <a class="button-form submit" href="javascript:void(null);" id="btn-submit" style="margin-right: 8px;"><img src="<?php echo site_url('images/btn-submit.png'); ?>" alt="" /><?php echo $this->lang->line('create'); ?></a>
                  <noscript><div><input type="submit" value="<?php echo $this->lang->line('save_changes'); ?>" /></div></noscript>
                </div>
                <div class="nextcol" style="margin: 0;">
                  <a class="button-form" id="btn-back" style="margin-right: 8px;" href="<?php echo site_url($module); ?>"><img src="<?php echo site_url('images/btn-back.png'); ?>" alt="" /><?php echo $this->lang->line('nav_cancel'); ?></a>
                </div>
                <div class="clear"></div>
              </div>
              </form>
            </div>
            